package com.aqie.easy.array;

/**
 * 999. 车的可用捕获量
 */
public class NumRookCaptures {
    public int numRookCaptures(char[][] board) {
        int R = board.length;
        int C = board[0].length;
        int rr =0, rc = 0;
        OUTER: for(int r = 0; r < R; r++){
            for(int c= 0; c < C; c++){
                if (board[r][c] == 'R'){
                    rr = r;
                    rc = c;
                    break OUTER;
                }
            }
        }
        // 上下左右运动
        int numP = 0;
        // 1. 向右移动
        for(int c = rc; c < C; c++){
            if (board[rr][c] == 'B'){
                break;
            }
            if (board[rr][c] == 'p'){
                numP ++;
                break;
            }
        }

        // 2. 向左移动
        for(int c = rc; c >= 0; c--){
            if (board[rr][c] == 'B'){
                break;
            }
            if (board[rr][c] == 'p'){
                numP ++;
                break;
            }
        }
        // 3.向上移动
        for(int r = rr; r >= 0; r--){
            if (board[r][rc] == 'B'){
                break;
            }
            if (board[r][rc] == 'p'){
                numP ++;
                break;
            }
        }

        // 4. 向下移动
        for(int r = rr; r < R; r++){
            if (board[r][rc] == 'B'){
                break;
            }
            if (board[r][rc] == 'p'){
                numP ++;
                break;
            }
        }
        return numP;
    }
}
